Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@turf/distance
Advanced tools
@turf/distance is a module of the Turf.js library, which provides geospatial analysis tools. This specific module calculates the distance between two geographical points using various measurement units such as miles, kilometers, and degrees.
Calculate Distance in Kilometers
This feature calculates the distance between two geographical points in kilometers. The 'from' and 'to' variables represent the coordinates of the two points.
const turf = require('@turf/distance');
const from = [0, 0];
const to = [1, 1];
const options = { units: 'kilometers' };
const distance = turf(from, to, options);
console.log(distance);
Calculate Distance in Miles
This feature calculates the distance between two geographical points in miles. The 'from' and 'to' variables represent the coordinates of the two points.
const turf = require('@turf/distance');
const from = [0, 0];
const to = [1, 1];
const options = { units: 'miles' };
const distance = turf(from, to, options);
console.log(distance);
Calculate Distance in Degrees
This feature calculates the distance between two geographical points in degrees. The 'from' and 'to' variables represent the coordinates of the two points.
const turf = require('@turf/distance');
const from = [0, 0];
const to = [1, 1];
const options = { units: 'degrees' };
const distance = turf(from, to, options);
console.log(distance);
Geolib is a library to provide basic geospatial operations like distance calculation, area calculation, and more. It offers similar functionalities to @turf/distance but also includes additional features like finding the center of a cluster of points.
Geodesy is a library for geodesic calculations, including distance and bearing between points, and conversions between different coordinate systems. It provides more advanced geospatial calculations compared to @turf/distance.
Spherical Geometry is a library for performing spherical geometry calculations, including distance and area calculations on the surface of a sphere. It is similar to @turf/distance but focuses on spherical geometry.
Calculates the distance between two points in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.
Parameters
from
Feature<Point> origin pointto
Feature<Point> destination pointunits
[string] can be degrees, radians, miles, or kilometers (optional, default kilometers
)Examples
var from = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-75.343, 39.984]
}
};
var to = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-75.534, 39.123]
}
};
var units = "miles";
var points = {
"type": "FeatureCollection",
"features": [from, to]
};
//=points
var distance = turf.distance(from, to, units);
//=distance
Returns number distance between the two points
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Install this module individually:
$ npm install @turf/distance
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
FAQs
turf distance module
The npm package @turf/distance receives a total of 1,328,205 weekly downloads. As such, @turf/distance popularity was classified as popular.
We found that @turf/distance demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.